package com.ruoyi.project.user.kknumber.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.user.kknumber.domain.KkNumber;
import com.ruoyi.project.user.kknumber.service.IKkNumberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * K号查询Controller
 *
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/user/kknumber")
public class KkNumberController extends BaseController {
    private String prefix = "user/kknumber";

    @Autowired
    private IKkNumberService kkNumberService;

    @RequiresPermissions("user:kknumber:view")
    @GetMapping()
    public String kknumber() {
        return prefix + "/kknumber";
    }

    @RequiresPermissions("user:kknumber:view")
    @GetMapping("/inner/{appId}/{kkid}")
    public String kknumberInner(@PathVariable("kkid") Long kkid, @PathVariable("appId") String appId, ModelMap mmap) {
        mmap.put("appId", appId);
        mmap.put("kkid", kkid);
        return prefix + "/kknumberInner";
    }

    /**
     * 查询K号查询列表
     */
    @RequiresPermissions("user:kknumber:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KkNumber kkNumber) {
        startPage();
        List<KkNumber> list = kkNumberService.selectKkNumberList(kkNumber);
        return getDataTable(list);
    }

    /**
     * 导出K号查询列表
     */
    @RequiresPermissions("user:kknumber:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KkNumber kkNumber) {
        List<KkNumber> list = kkNumberService.selectKkNumberList(kkNumber);
        ExcelUtil<KkNumber> util = new ExcelUtil<KkNumber>(KkNumber.class);
        return util.exportExcel(list, "kknumber");
    }

    /**
     * 新增K号查询
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存K号查询
     */
    @RequiresPermissions("user:kknumber:add")
    @Log(title = "K号查询", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KkNumber kkNumber) {
        return toAjax(kkNumberService.insertKkNumber(kkNumber));
    }

    /**
     * 修改K号查询
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        KkNumber kkNumber = kkNumberService.selectKkNumberById(id);
        mmap.put("kkNumber", kkNumber);
        return prefix + "/edit";
    }

    /**
     * 修改保存K号查询
     */
    @RequiresPermissions("user:kknumber:edit")
    @Log(title = "K号查询", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KkNumber kkNumber) {
        return toAjax(kkNumberService.updateKkNumber(kkNumber));
    }

    /**
     * 删除K号查询
     */
    @RequiresPermissions("user:kknumber:remove")
    @Log(title = "K号查询", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(kkNumberService.deleteKkNumberByIds(ids));
    }
}
